import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);
const xmlUtils = {
  getErmXml() {
    var datetime = new Date();
    var year = datetime.getFullYear();
    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
    var hour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
    var minute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
    var second = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
    let dateStr = year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
    let xml = `<?xml version="1.0" encoding="UTF-8"?>
    <diagram>
      <page_setting>
        <direction_horizontal>true</direction_horizontal>
        <scale>100</scale>
        <paper_size>A4 210 x 297 mm</paper_size>
        <top_margin>30</top_margin>
        <left_margin>30</left_margin>
        <bottom_margin>30</bottom_margin>
        <right_margin>30</right_margin>
      </page_setting>
      <category_index>0</category_index>
      <zoom>1.0</zoom>
      <x>0</x>
      <y>0</y>
      <default_color>
        <r>128</r>
        <g>128</g>
        <b>192</b>
      </default_color>
      <color>
        <r>255</r>
        <g>255</g>
        <b>255</b>
      </color>
      <font_name>Microsoft YaHei UI</font_name>
      <font_size>9</font_size>
      <settings>
        <database>MySQL</database>
        <capital>false</capital>
        <table_style></table_style>
        <notation></notation>
        <notation_level>0</notation_level>
        <notation_expand_group>true</notation_expand_group>
        <view_mode>2</view_mode>
        <outline_view_mode>1</outline_view_mode>
        <view_order_by>1</view_order_by>
        <auto_ime_change>false</auto_ime_change>
        <validate_physical_name>true</validate_physical_name>
        <use_bezier_curve>false</use_bezier_curve>
        <suspend_validator>false</suspend_validator>
        <export_setting>
          <export_ddl_setting>
            <output_path></output_path>
            <encoding></encoding>
            <line_feed></line_feed>
            <is_open_after_saved>true</is_open_after_saved>
            <environment_id>null</environment_id>
            <category_id>null</category_id>
            <ddl_target>
              <create_comment>true</create_comment>
              <create_foreignKey>true</create_foreignKey>
              <create_index>true</create_index>
              <create_sequence>true</create_sequence>
              <create_table>true</create_table>
              <create_tablespace>true</create_tablespace>
              <create_trigger>true</create_trigger>
              <create_view>true</create_view>
              <drop_index>true</drop_index>
              <drop_sequence>true</drop_sequence>
              <drop_table>true</drop_table>
              <drop_tablespace>true</drop_tablespace>
              <drop_trigger>true</drop_trigger>
              <drop_view>true</drop_view>
              <inline_column_comment>true</inline_column_comment>
              <inline_table_comment>true</inline_table_comment>
              <comment_value_description>true</comment_value_description>
              <comment_value_logical_name>false</comment_value_logical_name>
              <comment_value_logical_name_description>false</comment_value_logical_name_description>
              <comment_replace_line_feed>false</comment_replace_line_feed>
              <comment_replace_string></comment_replace_string>
            </ddl_target>
          </export_ddl_setting>
          <export_excel_setting>
            <category_id>null</category_id>
            <output_path></output_path>
            <template></template>
            <template_path></template_path>
            <used_default_template_lang></used_default_template_lang>
            <image_output></image_output>
            <is_open_after_saved>true</is_open_after_saved>
            <is_put_diagram>true</is_put_diagram>
            <is_use_logical_name>true</is_use_logical_name>
          </export_excel_setting>
          <export_html_setting>
            <output_dir></output_dir>
            <with_category_image>true</with_category_image>
            <with_image>true</with_image>
            <is_open_after_saved>true</is_open_after_saved>
          </export_html_setting>
          <export_image_setting>
            <output_file_path></output_file_path>
            <category_dir_path></category_dir_path>
            <with_category_image>true</with_category_image>
            <is_open_after_saved>true</is_open_after_saved>
          </export_image_setting>
          <export_java_setting>
            <java_output></java_output>
            <package_name></package_name>
            <class_name_suffix></class_name_suffix>
            <src_file_encoding></src_file_encoding>
            <with_hibernate>false</with_hibernate>
          </export_java_setting>
          <export_testdata_setting>
            <file_encoding></file_encoding>
            <file_path></file_path>
            <format>0</format>
          </export_testdata_setting>
        </export_setting>
        <category_settings>
          <free_layout>false</free_layout>
          <show_referred_tables>false</show_referred_tables>
          <categories>
          </categories>
        </category_settings>
        <translation_settings>
          <use>false</use>
          <translations>
          </translations>
        </translation_settings>
        <model_properties>
          <id></id>
          <height>-1</height>
          <width>-1</width>
            <font_name></font_name>
            <font_size>9</font_size>
          <x>50</x>
          <y>50</y>
          <connections>
          </connections>
          <display>false</display>
          <creation_date>${dateStr}</creation_date>
          <updated_date>${dateStr}</updated_date>
          <model_property>
            <name>Project Name</name>
            <value></value>
          </model_property>
          <model_property>
            <name>Model Name</name>
            <value></value>
          </model_property>
          <model_property>
            <name>Version</name>
            <value></value>
          </model_property>
          <model_property>
            <name>Company</name>
            <value></value>
          </model_property>
          <model_property>
            <name>Author</name>
            <value></value>
          </model_property>
        </model_properties>
        <table_properties>
          <schema></schema>
          <character_set></character_set>
          <collation></collation>
          <storage_engine></storage_engine>
          <primary_key_length_of_text>null</primary_key_length_of_text>
        </table_properties>
        <environment_setting>
          <environment>
            <id>0</id>
            <name>Default</name>
          </environment>
        </environment_setting>
      </settings>
      <dictionary>
      </dictionary>
      <tablespace_set>
      </tablespace_set>
      <contents>
      </contents>
      <column_groups>
      </column_groups>
      <test_data_list>
      </test_data_list>
      <sequence_set>
      </sequence_set>
      <trigger_set>
      </trigger_set>
      <change_tracking_list>
      </change_tracking_list>
    </diagram>
    `
    return xml;
  },
  creatTableContent(id, logical_name, physical_name, width, height, x, y) {
    // let tableDom = xmlDoc.createElement('table');
    // let id = 
    let table = `
    <table>
      <id>${id}</id>
      <height>${height}</height>
      <width>${width}</width>
        <font_name>Microsoft YaHei UI</font_name>
        <font_size>9</font_size>
      <x>${x}</x>
      <y>${y}</y>
      <color>
        <r>128</r>
        <g>128</g>
        <b>192</b>
      </color>
      <connections>
      </connections>
      <physical_name>${physical_name}</physical_name>
      <logical_name>${logical_name}</logical_name>
      <description></description>
      <constraint></constraint>
      <primary_key_name></primary_key_name>
      <option></option>
      <columns>
      </columns>
      <indexes>
      </indexes>
      <complex_unique_key_list>
      </complex_unique_key_list>
      <table_properties>
        <schema></schema>
        <character_set></character_set>
        <collation></collation>
        <storage_engine></storage_engine>
        <primary_key_length_of_text>null</primary_key_length_of_text>
      </table_properties>
    </table>`
    return table;
  },
  creatWordContent(word) {
    let dom = 
    `
    <word>
      <id>${word.word_id ? word.word_id : ''}</id>
      <length>${word.length ? word.length : 'null'}</length>
      <decimal>${word.decimal ? word.decimal : 'null'}</decimal>
      <array>${word.array ? word.array : 'false'}</array>
      <array_dimension>${word.array_dimension ? word.array_dimension : 'null'}</array_dimension>
      <unsigned>${word.unsigned ? word.unsigned : 'false'}</unsigned>
      <args>${word.args ? word.args : ''}</args>
      <zerofill>${word.zerofill ? word.zerofill : 'false'}</zerofill>
      <binary>${word.binary ? word.binary : 'false'}</binary>
      <description>${word.description ? word.description : ''}</description>
      <logical_name>${word.logical_name ? word.logical_name : ''}</logical_name>
      <physical_name>${word.physical_name ? word.physical_name : ''}</physical_name>
      <char_semantics>${word.char_semantics ? word.char_semantics : 'false'}</char_semantics>
      <type>${word.type ? word.type : ''}</type>
    </word>`
    return dom;
  },
  creatColumContent(colum) {
    let wordId = colum.word_id ? `<word_id>${colum.word_id}</word_id>` : ""
    let relation = colum.relation ? `<relation>${colum.relation}</relation>` : ""
    let referenced_column = colum.referenced_column ? `<referenced_column>${colum.referenced_column}</referenced_column>` : ""
    let c =
    '<normal_column>'+
      wordId +
      relation +
      referenced_column +
    `
      <id>${colum.id ? colum.id : ''}</id>
      <description>${colum.description ? colum.description : ''}</description>
      <unique_key_name>${colum.unique_key_name ? colum.unique_key_name : ''}</unique_key_name>
      <logical_name>${colum.logical_name ? colum.logical_name : ''}</logical_name>
      <physical_name>${colum.physical_name ? colum.physical_name : ''}</physical_name>
      <type>${colum.type ? colum.type : ''}</type>
      <constraint>${colum.constraint ? colum.constraint : ''}</constraint>
      <default_value>${colum.default_value ? colum.default_value : ''}</default_value>
      <auto_increment>${colum.auto_increment ? colum.auto_increment : 'false'}</auto_increment>
      <foreign_key>${colum.foreign_key ? colum.foreign_key : 'false'}</foreign_key>
      <not_null>${colum.not_null ? colum.not_null : 'false'}</not_null>
      <primary_key>${colum.primary_key ? colum.primary_key : 'false'}</primary_key>
      <unique_key>${colum.unique_key ? colum.unique_key : 'false'}</unique_key>
      <character_set>${colum.character_set ? colum.character_set : ''}</character_set>
      <collation>${colum.collation ? colum.collation : ''}</collation>
      <sequence>
        <name></name>
        <schema></schema>
        <increment></increment>
        <min_value></min_value>
        <max_value></max_value>
        <start></start>
        <cache></cache>
        <cycle>false</cycle>
        <order>false</order>
        <description></description>
        <data_type></data_type>
        <decimal_size>0</decimal_size>
      </sequence>
    </normal_column>`
    return c
  },
  creatNoteContent(note) {
    let dom = `
    <note>
      <id>${note.id}</id>
      <height>${note.height}</height>
      <width>${note.width}</width>
        <font_name>Microsoft YaHei UI</font_name>
        <font_size>9</font_size>
      <x>${note.x}</x>
      <y>${note.y}</y>
      <color>
        <r>128</r>
        <g>128</g>
        <b>192</b>
      </color>
      <connections>
      </connections>
      <text>${note.text}</text>
    </note>`
    return dom;
  },
  creatEdgeContent(edge) {
    let dom = `
    <relation>
      <id>${edge.id}</id>
      <source>${edge.sourceId}</source>
      <target>${edge.targetId}</target>
        <source_xp>-1</source_xp>
        <source_yp>-1</source_yp>
        <target_xp>-1</target_xp>
        <target_yp>-1</target_yp>
        <color>
          <r>0</r>
          <g>0</g>
          <b>0</b>
        </color>
      <child_cardinality>1..n</child_cardinality>
      <parent_cardinality>1</parent_cardinality>
      <reference_for_pk>true</reference_for_pk>
      <name></name>
      <on_delete_action>RESTRICT</on_delete_action>
      <on_update_action>RESTRICT</on_update_action>
      <referenced_column>null</referenced_column>
      <referenced_complex_unique_key>null</referenced_complex_unique_key>
    </relation>`
    return dom;
  },
  creatCommentEdgeContent(edge) {
    let dom = `
    <comment_connection>
      <id>${edge.id}</id>
      <source>${edge.sourceId}</source>
      <target>${edge.targetId}</target>
        <source_xp>-1</source_xp>
        <source_yp>-1</source_yp>
        <target_xp>-1</target_xp>
        <target_yp>-1</target_yp>
        <color>
          <r>0</r>
          <g>0</g>
          <b>0</b>
        </color>
    </comment_connection>`
    return dom;
  }
}
export default xmlUtils